package self.zhangkang.chart

import self.zhangkang.chart.data.KLineInfo

/**
 * @author : Android-张康
 * created on: 2023/8/23 13:52
 * description:
 */
object DataTools {

    /**
     * [KlineQuote] 转换为 [KLineInfo]
     *
     * @param klineQuote [KlineQuote]
     * @param preCLosePrice 昨收价
     */
    fun kLineQuoteToKLineInfo(klineQuote: KlineQuote, preCLosePrice: Float): KLineInfo {
        return KLineInfo(
            date = klineQuote.T.toLongOrNull() ?: 0L,
            openPrice = klineQuote.O.toFloatOrNull() ?: 0F,
            closePrice = klineQuote.C.toFloatOrNull() ?: 0F,
            avgPrice = klineQuote.V.toFloatOrNull() ?: Float.NaN,
            preCLosePrice = preCLosePrice,
            upOrDown = Float.NaN,
            adjustFlag = false,
            volume = klineQuote.VL.toDouble().toLong(),
            turnVolume = klineQuote.AM.toDouble().toLong() ?: 0L,
            highPrice = klineQuote.H.toFloatOrNull() ?: 0F,
            lowerPrice = klineQuote.L.toFloatOrNull() ?: 0F,
        )
    }


}